using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerPrimAttackState : PlayerState
{
    private float attackDir;
    private int comboCounter = 0;
    private float lastTimeAttacked = 0f;
    private float comboWindow = 2f;
    public PlayerPrimAttackState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        if (comboCounter > 2 || lastTimeAttacked + comboWindow < Time.time)
            comboCounter = 0;
        player.anim.SetInteger("ComboCounter", comboCounter);
        player.anim.speed = 1.1f;
        stateTimer = 0.1f;
        #region Choose Attack Direction
        attackDir = player.facingDir;
        if (xInput != 0)
        {
            attackDir = xInput;
        }
        #endregion
        player.setVelocity(player.attackMovement[comboCounter] * attackDir, rb.velocity.y);
        
    }

    public override void Exit()
    {
        base.Exit();
        comboCounter++;
        lastTimeAttacked = Time.time;
        player.StartCoroutine("BusyFor", 0.1f);
        player.anim.speed = 1f;
    }

    public override void Update()
    {
        base.Update();
        if (stateTimer < 0)
            player.SetZeroVelocity();
        if (triggerCalled)
        {
            stateMachine.ChangeState(player.idleState);
        }
    }
}
